home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
pcmagazi
/
1992
/
16
/
soundex.bas
< prev
next >
Wrap
BASIC Source File
|
1992-01-26
|
1KB
|
43 lines
DEFINT A-Z
DECLARE FUNCTION Soundex$ (Word$)
CLS
LOCATE 2, 32, 1
PRINT ">>> SOUNDEX <<<"
PRINT : PRINT
DO
LINE INPUT "Enter Last Name: "; LastName$
PRINT "Soundex Code: "; Soundex$(LastName$)
PRINT "Code Another Name (Y/N): ";
YN$ = UCASE$(INPUT$(1))
IF YN$ <> "Y" THEN END
PRINT : PRINT
LOOP
FUNCTION Soundex$ (Text$)
Word$ = UCASE$(Text$) 'work with a capitalized copy
Number$ = "01230120022455012623010202" 'table of SOUNDEX code values
SdxString$ = LEFT$(Word$, 1) 'start with the first letter
FOR I = 2 TO LEN(Word$) 'then consider what remains
E$ = MID$(Word$, I, 1) 'isolate this character
E = ASC(E$) - 64 'convert ASCII to table index
IF E >= 1 AND E <= 26 THEN 'accept only if it's a letter
This$ = MID$(Number$, E, 1) 'look this up in the table
IF This$ <> Prev$ AND This$ <> "0" THEN 'if different and not a vowel
Prev$ = This$ 'save the previous code
SdxString$ = SdxString$ + This$ 'build the output string
Prev$ = This$
END IF
END IF
NEXT I
'Pad the output with trailing zeros and then clip it to four characters.
Soundex$ = LEFT$(SdxString$ + "0000", 4)
END FUNCTION